<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xalan="http://xml.apache.org/xalan"
     exclude-result-prefixes="xalan"
     version="1.0">

<xsl:output method = "xml"      encoding="UTF-8"
              indent="yes" 
              xalan:indent-amount="2"/>


<xsl:template match="testResults">
<output>
<metainfo>someinfo</metainfo>
<httpsequence>
<xsl:element name="step">
 <xsl:attribute name="no"><xsl:text>1</xsl:text>
 </xsl:attribute> 


<xsl:for-each select="httpSample">
 <message>
  <httpmethod><xsl:value-of select="method"/> </httpmethod>
  <xsl:variable name="fullurl" select="java.net.URL"/>
  <httpURL>  
  
  <xsl:choose>
  
  <xsl:when test="contains($fullurl,'?')">
   <xsl:value-of select="substring-before($fullurl,'?')"/> 
  </xsl:when>
  <xsl:otherwise>
   <xsl:value-of select="$fullurl"/> 
  </xsl:otherwise>
  </xsl:choose>
  
  
  </httpURL>
  <xsl:variable name="urlparams" select="substring-after($fullurl,'?')"/>
  <xsl:variable name="tokenizedurlparams" select="xalan:tokenize($urlparams,'&amp;')"/>
  
  <xsl:for-each select="$tokenizedurlparams">
  	<xsl:variable name="key-val" select="."/>
     <xsl:variable name="key" select="substring-before($key-val,'=')"/>
     <xsl:variable name="val" select="substring-after($key-val,'=')"/>
     <xsl:element name="URLparameter">
     <xsl:attribute name="name"> <xsl:value-of select="$key"/>
      </xsl:attribute> <xsl:value-of select="$val"/>
      </xsl:element>
    </xsl:for-each>
  <payload> <xsl:value-of select="queryString"/> </payload>
  
  <response> <xsl:value-of select="responseData"/> </response>
  
 </message>
 </xsl:for-each>

</xsl:element>
</httpsequence>  
 
 </output>
</xsl:template>

</xsl:stylesheet> 
